home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
GRAPH_FO
/
(GRAPH
/
GRAPH_SO
/
GRLIST.C
< prev
next >
Wrap
Text File
|
1991-02-12
|
5KB
|
201 lines
/******************************************************************************
GrList.c
Graph methods in Object C.
SUPERCLASS = CList
Copyright ⌐ 1991 Maarten Meijer. All rights reserved.
CIS 100016,1764; FidoNet 2:512/114
*******************************************************************************/
#include "GrList.h"
/******************************************************************************
IGrList
Initialize GrList
*******************************************************************************/
void
GrList::IGrList() {
inherited::IList(); /* CList */
}
/******************************************************************************
Draw
Draw all GrNodes inside an area, being inside is determined by the
GrNode method NodeInRect().
*******************************************************************************/
static void /* NOT a method !! */
_DrawAllRect(GrNode *theNode, Rect *area) {
Point loc;
if(theNode->NodeInRect(area)) {
theNode->Draw();
theNode->SetRegion();
}
/*
should region also be set when outside the drawing area or does
the region need to be set every time the node is drawn?
*/
}
void
GrList::Draw(Rect *area) {
CCluster::DoForEach1(_DrawAllRect, (long)area);
}
/******************************************************************************
_Draw
Draw all irrespective of area without erasing.
Used for edgeList drawing, but not functioning well.
*******************************************************************************/
static void /* NOT a method !! */
_DrawAll(GrNode *this) {
this->_Draw();
}
void
GrList::_Draw() {
CCluster::DoForEach(_DrawAll);
}
static void /* NOT a method !! */
_SelectAll(GrNode *this, Rect *r) {
if(this->NodeInRect(r)) { /* Not exact, see IM I-185 */
this->Select();
this->Draw();
}
}
void
GrList::Select(Rect *r) {
CCluster::DoForEach1(_SelectAll, (long)r);
}
static void /* NOT a method !! */
_DeselectAll(GrNode *this) {
if(this->Selected()) {
this->Deselect();
this->Draw();
}
}
void
GrList::Deselect() {
CCluster::DoForEach(_DeselectAll);
}
static long count;
static void
_CountSelected(GrNode *this) {
if(this->Selected())
count++;
}
long
GrList::CountSelected() {
count = 0L;
CCluster::DoForEach(_CountSelected);
return count;
}
static Boolean
_Selected(GrNode *this) {
return (this->Selected());
}
GrNode *
GrList::GetSelected() {
GrNode *found;
found = (GrNode *)CList::FirstSuccess(_Selected);
if(found != NULL)
SendBack(found); /* so you can loop thru the whole list */
return found;
}
/******************************************************************************
AddNode & RemoveNode
Adding and removing nodes from the GrList.
*******************************************************************************/
void
GrList::AddNode(GrNode *which) {
inherited::Append(which); /* Clist */
}
void
GrList::RemoveNode(GrNode *which) {
CList::Remove(which); /* CList remove from list */
which->Dispose(); /* and dispose of it */
}
/******************************************************************************
FindNode
Find the node that was clicked on.
*******************************************************************************/
static Boolean /* NOT a method !! */
_FindNode(GrNode *this, Point where) {
if(this->PtInNode(where))
return true;
else
return false;
}
GrNode *
GrList::FindNode(Point where) {
GrNode *node;
node = (GrNode *)CList::LastSuccess1(_FindNode, *(long *)&where);
return node;
}
/******************************************************************************
FindIncident
Find connected edges to a vertex, unable to loop thru all, this
would be possible with a move to back/front alogoritm.
*******************************************************************************/
static Boolean /* NOT a method !! */
_FindIncident(GrNode *this, GrNode *which) {
return this->Incident(which);
}
GrNode *
GrList::FindIncident(GrNode *which) {
return (GrNode *)CList::FirstSuccess1(_FindIncident,
(long)which);
}
/******************************************************************************
SpanningRect
Find the rect that encloses all edges connected to a vertex,
and edges going thru the area vacated by the vertex.
*******************************************************************************/
static Rect vertexRect, /* the rect of the vertex */
resultRect; /* the rect enclosing all edges */
static void
_SpanningRect(GrNode *this, GrNode *which) {
Rect edgeRect; /* the rect of each edge */
if( this->Incident(which) ) {
this->GetRect(&edgeRect);
UnionRect(&edgeRect, &resultRect, &resultRect);
}
}
void
GrList::SpanningRect(GrNode *which, Rect *rect) {
which->GetRect(&resultRect);
CCluster::DoForEach1(_SpanningRect, (long)which);
*rect = resultRect;
}